package Texas.Card;
import java.util.*;

public final class CardDeck {
	private static CardDeck _instance; 
	private ArrayList<Card> _cards = new ArrayList<Card>();
	private ArrayList<Card> _mixedCards;
	
	private CardDeck() {
		for (CardSuit cardSuit : CardSuit.values())
			for(CardRank cardRank : CardRank.values())
				_cards.add(new Card(cardSuit, cardRank));
		_mixedCards = new ArrayList<Card>(_cards);		
	}
	
	public static CardDeck getInstance() {
		if(_instance == null)
			_instance = new CardDeck();
		return _instance;
	}
	
	public void shuffle() {
		if(!_mixedCards.isEmpty()) {
			_mixedCards.clear();
			_mixedCards = new ArrayList<Card>(_cards);
		}
		
		Collections.shuffle(_mixedCards);
	}
		
	public Card pop() {
		Card card = _mixedCards.get(_mixedCards.size()-1);
		_mixedCards.remove(_mixedCards.size()-1);
		return card;
	}
}
